Skip to content

The LLVM Backend Implementation#13

Draft
vbxq wants to merge 315 commits into
masterfrom
feat/llvm
Draft

The LLVM Backend Implementation#13
vbxq wants to merge 315 commits into
masterfrom
feat/llvm

Conversation

@vbxq
Copy link
Copy Markdown
Owner

@vbxq vbxq commented Feb 25, 2026

LLVM Backend Implementation (v0.21.x)

Here you can track the implementation progress !

There is a VERY strong chance that this plan will change, but for now, here is what I had initially planned
Bug fixes/other change they will be written in the changelog and not here

Foundation (v0.21.0-a -> v0.21.5-a)

  • AIR (Aelys Intermediate Representation) implementation (v0.20.1-a)
  • System V AMD64 layout pass (v0.20.1-a)
  • Monomorphization for generics (v0.20.3-a)
  • LLVM backend skeleton via inkwell (v0.21.0-a)
  • Hello world compiles and runs natively (v0.21.2-a)
  • aelys-core runtime in C (minimal syscall wrappers) (v0.21.2-a)
  • Delete the virtual machine

1. Usable Backend (v0.21.3-a -> v0.21.5-a)

goal : write and debug very simple scripts (so that means small calculations, strings, conditions, loops, and functions)

  • println supports primitive types (i64, f64, bool) (v0.21.5-a)
  • Logical negation operator ! (v0.21.5-a)
    • AIR lowering (v0.21.5-a)
    • LLVM codegen (xor i1) (v0.21.5-a)
  • String comparison operators (v0.21.5-a)
    • __aelys_str_eq (C, bootstrap only) (v0.21.5-a)
    • == and != for strings (v0.21.5-a)
  • End-to-end tests (v0.21.5-a)

2. Stack Arrays

goal : arrays functional for real code

  • Stack-allocated arrays [T; N]
    • Codegen: alloca [N x T] with initialization stores
    • No runtime calls, pure LLVM IR
    • Bounds checking (compile-time for constants, runtime for variables)
  • Array indexing read & write
  • Tests for this

3. Enums and Pattern Matching

goal : make proper error handling possible (inspired by rust)

  • Basic enums
    • Type definition and parsing
    • LLVM codegen for enum construction
  • Pattern matching
    • match expression lowering to AIR
    • Basic blocks with switch IR generation
    • Exhaustiveness checking
  • Generic enums (Option, Result)
  • Tests for error handling patterns

4. Standard Library Bootstrap

goal : stdlib written in Aelys itself

  • std.mem - allocator wrappers
  • std.string - to_string, concat, etc
  • std.io
  • std.collections - Vec, HashMap
  • remove all bootstrap-only functions from aelys-core

5. GC Implementation

  • Arena allocator in std.gc (pure Aelys)
  • Tracing GC (mark-and-sweep or copying)
  • Write barriers insertion by compiler
  • GC enabled by default, opt-out via @no_gc or #![no_gc] (file-wise)

6. Mini Borrow Checker

goal: @no_gc mode is memory-safe too without GC overhead
goal²: not reimplement rust and actually make it the system easy for newcomers

  • lifetime annotation syntax (&[T])
  • Basic lifetime analysis (outlive checking)
  • Single mutable or multiple immutable borrows
  • Intentionally avoids complex Rust features.. otherwise what's the point
  • DX focus

Grand final

  • FFI with C and Rust
  • Modules and imports testing
  • Closures
  • Static variable declaration

Architecture

flowchart TD
    A[User written .aelys code] --> B[Lexer]
    B --> C[Parser]
    C --> D[Semantical analysis and type inference]
    D --> AIR_LABEL[Aelys Intermediate Representation]
    D -. legacy path .-> V[Old Aelys Virtual Machine]

    AIR_LABEL --> L1

    subgraph BUILD[AIR build]
        direction TB
        L1[Lower] --> L2[Layout]
        L2 --> L3[Monomorph]
        L3 -- rebuild when needed --> L1
    end

    L3 --> P1

    subgraph OPT[AIR opt passes]
        direction TB
        P1[Copy elim] --> P2[Dead locals]
        P2 --> P3[Other passes]
        P3 -- iterate until stable --> P1
    end

    P3 --> G[LLVM codegen]
    G --> H[LLVM IR]
    H --> N[Native binary code from LLVM backend]
Loading

@vbxq vbxq self-assigned this Feb 25, 2026
@vbxq vbxq added the enhancement New feature or request label Feb 25, 2026
vbxq added 28 commits February 26, 2026 08:39
vbxq added 29 commits April 2, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant